import axios from 'axios';

const service = axios.create({
    baseURL: "", //
    timeout: 10000
});


service.interceptors.request.use(config => {
        let headers = {
            'Content-Type': 'multipart/form-data;charset=UTF-8'
        }
        let AccessToken = sessionStorage.getItem('AccessToken');
        if (AccessToken) {
            headers.AccessToken = AccessToken;
        }
        config.headers = headers;
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject().then(r => {
                console.log('请求配置有错啊', r);
            });
            return "server error";
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
